package xyz.prob.kun.biz.modules.system.controller;

import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import xyz.prob.kun.biz.modules.system.params.LoginUserParam;
import xyz.prob.kun.biz.modules.system.params.SysUserRegisterParam;
import xyz.prob.kun.biz.modules.system.service.SysUserService;
import xyz.prob.kun.common.model.AjaxResult;

@RestController
@RequestMapping("system")
@Tag(name = "测试doc")
public class SysUserController {

    @Resource
    private SysUserService sysUserService;
    @GetMapping("hello")
    @PreAuthorize("hasRole('admin')")
    public AjaxResult sysHello(){
        return AjaxResult.success("hello world");
    }

    @GetMapping("hello2")
    @PreAuthorize("hasPermission('admin')")
    public AjaxResult sysHello2(){
        throw new RuntimeException();
       // return AjaxResult.success("hello world");
    }


    @PostMapping("login")
    public AjaxResult<String> login(@RequestBody LoginUserParam loginUserParam){
        return AjaxResult.success("登陆成功", sysUserService.login(loginUserParam));
    }

    @PostMapping("register")
    public AjaxResult<String> register(@RequestBody SysUserRegisterParam registerParam){
        return AjaxResult.success("注册成功", sysUserService.register(registerParam));
    }
}
